package org.bing.engine.jmx;

import static java.lang.management.ManagementFactory.RUNTIME_MXBEAN_NAME;
import static java.lang.management.ManagementFactory.newPlatformMXBeanProxy;

import java.lang.management.RuntimeMXBean;
import java.util.Map;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;

public class MBeanTracer {

    public void trace(JMXConnector jmxc) {
        try {
            doTrace(jmxc);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void doTrace(JMXConnector jmxc) throws Exception {
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        RuntimeMXBean runtimeMBean = newPlatformMXBeanProxy(mbsc, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
        // List<String> args = runtimeMBean.getInputArguments();
        Map<String, String> map = runtimeMBean.getSystemProperties();
        // System.out.println(args);
        System.out.println("engine.guid" + ":" + map.get("engine.guid"));
    }
}
